#ifndef __LIB_LIST_CONTROL_H
#define __LIB_LIST_CONTROL_H

#include <stdlib.h>
#include <windows.h>


typedef struct {
	void *		data;
	size_t		item_size;
	int			num;
	int			alloc_num;
} LIST;

typedef BOOL LIST_OP_RULE( void * item, UINT32 param );


#ifdef __cplusplus
extern "C" {
#endif


#define List_New(type)					List_New_(sizeof(type), 0)
#define List_New2(type, num)			List_New_(sizeof(type), (num))
LIST * List_New_( size_t item_size, int num );
void List_Delete( LIST * list );

#define List_Init(list, type)			List_Init_(list, sizeof(type), 0)
#define List_Init2(list, type, num)		List_Init_(list, sizeof(type), (num))
int List_Init_( LIST * list, size_t item_size, int num );
#define List_Uninit(list)				List_Clear(list);
void List_Clear( LIST * list );

int List_GetNum( LIST * list );
void * List_GetItem( LIST * list, int idx );

int List_InsertItem( LIST * list, const void * item, int idx );
int List_AppendItem( LIST * list, const void * item );

int List_FindItem( LIST * list, const void * item );
int List_FindItemEx( LIST * list, LIST_OP_RULE * cmp_rule, UINT32 param );

int List_DeleteItem( LIST * list, int idx );

int List_Copy( LIST * dst, const LIST * src );
int List_CopyEx( LIST * dst, const LIST * src,
	LIST_OP_RULE * copy_rule, UINT32 param );
LIST * List_MakeCopy( const LIST * list );
LIST * List_MakeCopyEx( const LIST * list,
	LIST_OP_RULE * copy_rule, UINT32 param );
/*
int List_WriteFile( LIST * list, FILE_HANDLE_T f );
int List_ReadFile( LIST * list, FILE_HANDLE_T f );
*/

#ifdef __cplusplus
} /* extern "C" */
#endif

#endif

